<?
	cria_variaveis($_POST,$_GET,$_FILES); 
?>
<p class="titulo" align="center"><?php echo $msg->get("MULTIPLICACAO_MSG_02") ?></p>
<p class="subtitulo" align="center"><?php echo $msg->get("MULTIPLICACAO_MSG_03") ?></p>
<p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=multiplicacao.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get("Material_Teorico") ?></a></li>
    <li><a href="index.php?inc=multiplicacao.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get("Exemplos_Prontos") ?></a></li>
    <li><a href="index.php?inc=multiplicacao.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get("Entrada_Teclado") ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
if (!isset($Calcular)) {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
    {
        require_once("./classes/upload.php");
        $uploads = new Upload();
        $uploads->Lista("matriz");
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
    { //leitura de dados via banco de dados - modulo de exemplos e exercicios
        include "exibe_prob_matriz_mul_xml.php";
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado")
    {
        if ((strlen($rows)==0)or($rows<0)or($columns<0)or(strlen($columns)==0)or(strlen($rows2)==0)or($rows2<0)or($columns2<0)or(strlen($columns2)==0)or($columns!=$rows2) )
        {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=multiplicacao.php>";
            if ( (strlen($columns)!=0) and (strlen($rows2)!=0) and ($columns!=$rows2) )
                echo $msg->get("MULTIPLICACAO_MSG_10")."<br><br>";
            echo $msg->get("MULTIPLICACAO_MSG_04");
            echo "<input type=text size='2' maxlength='2' name=rows value=".($rows).">";
            echo "X";
            echo "<input type=text size='2' maxlength='2' name=columns value=".($columns).">";
            echo "<br><br>";
            echo $msg->get("MULTIPLICACAO_MSG_09");
            echo "<input type=text size='2' maxlength='2' name=rows2 value=".($rows2).">";
            echo "X";
            echo "<input type=text size='2' maxlength='2' name=columns2 value=".($columns2).">";
            echo "<br><br>";
            echo "<input type=hidden name=executar value=sim>";
            echo "<input class=button type=submit name=Submit value=".($msg->get('G_MSG_02')).">";
            echo "</form>";
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=multiplicacao.php>";
            echo "<input class=button type=submit name=Submit value=".($msg->get('G_MSG_03')).">";
            echo "</form>";
        }
        elseif (!checaNumerico($rows) || !checaNumerico($columns) || !checaNumerico($rows2) || !checaNumerico($columns2))
        {
    ?>
            <p><font color="red"><?php echo $msg->get("Apenas_Dados_Numericos") ?></font></p>
            <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
    <?php
        }
        else
        {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=multiplicacao.php>";
            //echo MULTIPLICACAO_MSG_04;
            echo "<input type=hidden name=rows value=".($rows).">";
            //echo "X";
            echo "<input type=hidden name=columns value=".($columns).">";
            //echo "<br><br>";
            //echo MULTIPLICACAO_MSG_04;
            echo "<input type=hidden name=rows2 value=".($rows2).">";
            //echo "X";
            echo "<input type=hidden name=columns2 value=".($columns2).">";
            echo "<br><br>";
            echo "<p align=left><font face=Arial>".$msg->get('MULTIPLICACAO_MSG_05')."</font>";
            echo "<nobr>";
            for ($i=0; $i<$rows; $i++) {
                echo "<br><br>";
                for ($j=0; $j<$columns; $j++) {
                    echo "<input type=text name=A[".($i)."][".($j)."] maxlength=10 size=5 value=".($A[$i][$j]).">";
                } //end forj
            } //end fori
            echo "</nobr>";
            echo "<p>";
            echo "<p align=left><font face=Arial>".$msg->get('MULTIPLICACAO_MSG_06')."</font>";
            echo "<nobr>";
            for ($i=0; $i<$rows2; $i++) {
                echo "<br><br>";
                for ($j=0; $j<$columns2; $j++) {
                    echo "<input type=text name=B[".($i)."][".($j)."] maxlength=10 size=5 value=".($B[$i][$j]).">";
                } //end forj
            } //end fori
            echo "</nobr>";
            echo "<p>";
            echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
            echo "<br>";
            echo "</form>";
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=multiplicacao.php>";
            echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
            echo "</form>";
        } //end if
        echo "</body>";
    }
} else {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
        verificaBib($xml_file);echo "<br>";
    if (!checaNumerico($rows) || !checaNumerico($columns) || !checaNumerico($rows2) || !checaNumerico($columns2) || !checaNumerico($A) || !checaNumerico($B))
    {
?>
        <p><font color="red"><?php echo $msg->get('Apenas_Dados_Numericos') ?></font></p>
        <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
<?php
    }
    else
    {
        echo $msg->get('MULTIPLICACAO_MSG_04');
        echo " $rows X $columns";
        echo "<br><br>";
        echo $msg->get('MULTIPLICACAO_MSG_09');
        echo " $rows2 X $columns2";
        echo "<br><br>";
        echo "<table border=\"0\">";
        echo "<tr><td align=\"center\">".$msg->get('MULTIPLICACAO_MSG_05')."</td><td>&nbsp;</td><td align=\"center\">".$msg->get('MULTIPLICACAO_MSG_06')."</td><td>&nbsp;</td><td align=\"center\">".$msg->get('MULTIPLICACAO_MSG_08')."</td></tr>";
        echo "<tr><td align=\"center\">";
        echo "<table border=\"0\">";
        for ($i=0; $i<$rows; $i++) {
        echo "<tr>";
        for ($j=0; $j<$columns; $j++) {
                echo "<td width=\"40\" align=\"center\" valign=\"center\">".$A[$i][$j]."</td>";
        } //end forj
        echo "</tr>";
        } //end fori
        echo "</table></td><td valign=\"center\" align=\"center\">x</td><td align=\"center\">";
        echo "<table border=\"0\">";
        for ($i=0; $i<$rows2; $i++) {
        echo "<tr>";
        for ($j=0; $j<$columns2; $j++) {
                echo "<td width=\"40\" align=\"center\" valign=\"center\">".$B[$i][$j]."</td>";
        } //end forj
        echo "</tr>";
        } //end fori
        echo "</table></td><td valign=\"center\" align=\"center\">=</td><td align=\"center\">";
        for ($i=0; $i<$rows; $i++) {
        for ($j=0; $j<$columns2; $j++) {
            $C[$i][$j]=0;
            for ($k=0;$k<$columns;$k++) {
                $C[$i][$j]=$C[$i][$j]+$A[$i][$k]*$B[$k][$j];
            }
        }
        }
        echo "<table border=\"0\">";
        for ($i=0; $i<$rows; $i++) {
        echo "<tr>";
        for ($j=0; $j<$columns2; $j++) {
                echo "<td width=\"40\" align=\"center\" valign=\"center\">".$C[$i][$j]."</td>";
        } //end forj
        echo "</tr>";
        } //end fori
        echo "</table>";
        echo "</td></tr></table>";
        echo "<br>".$msg->get('Somas_Parciais').":<br>";
        for ($i=0; $i<$rows; $i++) {
            for ($j=0; $j<$columns2; $j++) {
                $C[$i][$j]=0;
                echo "C<sub>".($i+1).($j+1)."</sub>=";
                for ($k=0;$k<$columns;$k++) {
                    if ($k != 0) echo "+";
                    $C[$i][$j]=$C[$i][$j]+$A[$i][$k]*$B[$k][$j];
                    echo $A[$i][$k]."*".$B[$k][$j];
                }
                echo "=".$C[$i][$j];
                echo "<br>";
            }
        }
        echo "</form>";
        echo "<p>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
        {
            echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
            echo "<script language=\"javascript\" type=\"text/javascript\">\n";
            echo "function criarLinks(value) {\n";
            echo "document.exemplos.indice.value = value;\n";
            echo "document.exemplos.action = 'index.php?inc=multiplicacao.php&modo=exemplo'\n";
            echo "document.exemplos.submit();\n";
            echo "}\n";
            echo "</script>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\">";
            echo $msg->get('Outros_Exemplos')."<br>";
            $objeto = new DomDocument();
            $objeto->load($xml_file);
            $filho = $objeto->getelementsbytagname("matrices");
            if ($filho->length > 0)
            {
                $temp = $filho->item(0)->getelementsbytagname("matrix");
                $j = 0;
                for($i = 0; $i < $temp->length; $i++)
                {
                    $rows = $temp->item($i)->getelementsbytagname("num_rows");
                    $cols = $temp->item($i)->getelementsbytagname("num_cols");
                    if ($rows->length > 1)
                    {
                            echo ($j == 0) ? '' : ' | ';
                            echo "<a class=\"bibliotecaexemplos\" href=\"javascript:criarLinks(".$j.")\" title=\"";
                            echo "Matriz (".$rows->item(0)->nodeValue."x".$cols->item(0)->nodeValue.")x(";
                            echo $rows->item(1)->nodeValue."x".$cols->item(1)->nodeValue.")\">";
                            echo ($j == $indice)?"<b><u>":"<u>";
                            echo ($j+1);
                            echo ($j == $indice)?"</b></u>":"</u>";
                            echo "</a>";
                            $j++;
                        }
                }
            }
            echo "<br /> <br />";
        }
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=multiplicacao.php>";
        echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
        echo "</form>";
    }
}
?>
</div>